<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>添加影视</h2>
<form id="fo"  >
    <input type="hidden" name="id" id="id" >
    <table>
        <tr>
            <td>影视名称：</td>
            <td><input type="text" id="title" name="title" placeholder="请输入影视名称"> </td>
        </tr>
        <tr>
            <td>主演：</td>
            <td><input type="text" name="actors" id="actors"  placeholder="请输入主演"> </td>
        </tr>
        <tr>
        <tr>
            <td>选择分类：</td>
            <td><select name="category" id="category">
                <option value="">全部</option>
                <option value="电视剧">电视剧</option>
                <option value="电影">电影</option></select></td>
        </tr>
        <tr>
        <tr>
            <td>选择语言：</td>
            <td>
                <select name="languageId" id="languageId">
                <option value="0">全部</option>
            </select>
            </td>
        </tr>
        <tr>
            <td>集数：</td>
            <td><input type="text" name="nums"  id="nums" placeholder="请输入集数"> </td>
        </tr>
        <tr>
            <td>相关操作:</td>
            <Td><input type="button" value="提交" onclick="fnn()"> <input type="button"  value="返回" onclick="fan()"></Td>
        </tr>

    </table>
</form>

</body>
<script th:src="@{https://code.jquery.com/jquery-3.5.1.min.js}" src="js/jquery.js"></script>
<script>

    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "/selectAll",
            dataType: "json",
            success: function (data) {
                //获取model中roleId
                // var brandId = [[${languageId}]];
                // alert("json："+data);
                for (var i in data) {
                    var op = "<option ";
                    // if (data[i].id == languageId) {
                    //     op += " selected='selected' ";
                    // }
                    op += " value='" + data[i].id + "'>" + data[i].name + "</option>";
                    $("#languageId").append(op);
                }
            },
            error: function (data) {
                alert("对不起，获取数据失败！");
            }
        });
        let pa=window.location.search.substring(1);
       let id = pa.split("=")[1];
        $.getJSON('selectOne?id='+id,function (data) {
                $("#id").val(data.id);
                $("#title").val(data.title);
                $("#actors").val(data.actors);
                $("#category").val(data.category);
                $("#languageId").val(data.languageId);
                $("#nums").val(data.nums);
        })

    });
    function fnn() {
        $.post("/update",$("#fo").serialize(),function (data) {
            if (data.reult==true){
                alert("提交成功");
                window.location.href='/index';
            }else{
                alert("提交失败")
            }
        },"json")
    }


</script>
</html>